package com.yc.jpyy.oadoc.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.yc.jpyy.base.service.BaseService;
import com.yc.jpyy.base.util.PageBean;
import com.yc.jpyy.oadoc.dao.OADocDao;
import com.yc.jpyy.oadoc.service.OADocService;





@Service
public class OADocServiceImpl extends BaseService implements OADocService {
    
	@Autowired
	private OADocDao oaDocDao;

	

	@Override
	public int addOADocService(Map<String, Object> paramsMap) throws DataAccessException {
		int ret = oaDocDao.addOADocDao(paramsMap);
		System.out.println(ret);
		return ret;
	}

	@Override
	public int updateOADocService(Map<String, Object> paramsMap) throws DataAccessException {
		int ret = oaDocDao.updateOADocDao(paramsMap);
		return ret;
		
	}

	
	
	

	@Override
	public Map<String, Object> findOADocByIDServer(Map<String, Object> paramsMap) throws DataAccessException {
	     return oaDocDao.findOADocByIdDao(paramsMap);
	}

	

	@Override       
	public PageBean findOADocService(Map<String, Object> paramsMap) throws DataAccessException {
		int pagenum = Integer.parseInt(paramsMap.get("pagenum").toString());
		int pagesize = Integer.parseInt(paramsMap.get("pagesize").toString());
		paramsMap.put("pagestart", (pagenum-1) * pagesize);
		List<Map<String, Object>> list = oaDocDao.findOADocDao(paramsMap);
		PageBean pageBean = new PageBean();
		pageBean.setList(list);
		// 每页几条数据，默认20条
		pageBean.setPageSize(pagesize);
		// 得到数据库中的条数
		pageBean.setAllRow(this.findCountOADocService(paramsMap));
		// 当前第几页，默认第一页
		pageBean.setCurrentPage(pagenum);
		// 得到一共几页
		pageBean.setTotalPage(pageBean.getTotalPage());
		// 模仿百度分页，只显示10条数据
		pageBean.paginationTool(pagenum, pageBean.getTotalPage());
		return pageBean;
	}

	@Override
	public int findCountOADocService(Map<String, Object> paramsMap) throws DataAccessException {
		return oaDocDao.findCountOADocDao(paramsMap);
	}

	@Override
	public int delOADocService(Map<String, Object> InvestigInfo) throws DataAccessException {
		return oaDocDao.delOADocDao(InvestigInfo);
	}

	@Override
	public int updateOADocFileService(Map<String, Object> paramsMap) throws DataAccessException {
		// TODO Auto-generated method stub
		return oaDocDao.updateOADocFileDao(paramsMap);
	}

	@Override
	public PageBean findOADocToOADocItemService(Map<String, Object> paramsMap) throws DataAccessException {
		int pagenum = Integer.parseInt(paramsMap.get("pagenum").toString());
		int pagesize = Integer.parseInt(paramsMap.get("pagesize").toString());
		paramsMap.put("pagestart", (pagenum-1) * pagesize);
		String[] status = paramsMap.get("status").toString().equals("")?null:paramsMap.get("status").toString().split(",");
		paramsMap.put("status",status);
		List<Map<String, Object>> list = oaDocDao.findOADocToOADocItemDao(paramsMap);
		PageBean pageBean = new PageBean();
		pageBean.setList(list);
		// 每页几条数据，默认20条
		pageBean.setPageSize(pagesize);
		// 得到数据库中的条数
		pageBean.setAllRow(this.findCountOADocToOADocItemService(paramsMap));
		// 当前第几页，默认第一页
		pageBean.setCurrentPage(pagenum);
		// 得到一共几页
		pageBean.setTotalPage(pageBean.getTotalPage());
		// 模仿百度分页，只显示10条数据
		pageBean.paginationTool(pagenum, pageBean.getTotalPage());
		return pageBean;
	}

	@Override
	public int findCountOADocToOADocItemService(Map<String, Object> paramsMap) throws DataAccessException {
		// TODO Auto-generated method stub
		return oaDocDao.findCountOADocToOADocItemDao(paramsMap);
	}

	
	


	
}
